package cn.lyf.dao;

import cn.lyf.entity.Body;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;



@Repository
public class BodyDaoImpl implements BodyDao {
    @Autowired
    MongoTemplate mongoTemplate;

     //添加博客内容
    //返回新添加的bodyid
    @Override
    public String add(Body body) {
        Body b = mongoTemplate.insert(body);
        System.out.println("bodyid=="+b.getId());
        return  b.getId();
    }

    //根据博客id查找博客的内容
    @Override
    public Body findOneBody(String bodyid) {
        Query query = new Query(Criteria.where("id").is(bodyid));
        return mongoTemplate.findOne(query,Body.class);
    }
}
